#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> ans(n, INT_MIN);
        int a = 0;
        while (a != n)
        {
            int cmp = nums[a];
            for (int i = (a + 1) % n; i != a; i = (i + 1) % n)
            {
                if (nums[i] > cmp)
                {
                    ans[a] = nums[i];
                    break;
                }
            }
            if (ans[a] == INT_MIN)
                ans[a] = -1;
            ++a;
        }
        return ans;
    }
};